<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <title>Hoodoo::Presenters::Embedding::Embeds</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <link rel="stylesheet" href="../../../../css/reset.css" type="text/css" media="screen" />
<link rel="stylesheet" href="../../../../css/main.css" type="text/css" media="screen" />
<link rel="stylesheet" href="../../../../css/github.css" type="text/css" media="screen" />
<script src="../../../../js/jquery-1.3.2.min.js" type="text/javascript" charset="utf-8"></script>
<script src="../../../../js/jquery-effect.js" type="text/javascript" charset="utf-8"></script>
<script src="../../../../js/main.js" type="text/javascript" charset="utf-8"></script>
<script src="../../../../js/highlight.pack.js" type="text/javascript" charset="utf-8"></script>

</head>

<body>
    <div class="banner">
        <h1>
            <span class="type">Class</span>
            Hoodoo::Presenters::Embedding::Embeds
                <span class="parent">&lt;
                    <a href="Embeddable.html">Hoodoo::Presenters::Embedding::Embeddable</a>
                </span>
        </h1>
        <ul class="files">
            <li><a href="../../../../files/lib/hoodoo/presenters/embedding_rb.html">lib/hoodoo/presenters/embedding.rb</a></li>
        </ul>
    </div>
    <div id="bodyContent">
        <div id="content">
    <div class="description">
      
<p>Instantiate this class and add one, or an <a href="../Array.html">Array</a>
of fully rendered resource objects to it via the API described in the base
class, <a
href="Embeddable.html">Hoodoo::Presenters::Embedding::Embeddable</a>. You
can then pass it to the likes of <a
href="../Base.html#method-c-render_in">Hoodoo::Presenters::Base.render_in</a>
via the <code>options</code> parameter to have the embed data included in
the fully rendered end result.</p>

<p>When a request arrives to embed data for a particular resource or list of
resources (in which case, do the following for each item in that list):</p>
<ul><li>
<p>Render the embedded resource(s)</p>
</li><li>
<p>Create an instance of this class</p>
</li><li>
<p>Add the rendered resource representations using this class&#39;s API</p>
</li><li>
<p>Use <a
href="../Base.html#method-c-render_in">Hoodoo::Presenters::Base.render_in</a>
to render the final, target resource, passing in the embed collection via
the <code>options</code> <a href="../Hash.html">Hash</a>.</p>
</li></ul>

<p>Simple example:</p>

<pre><code>embeds = Hoodoo::Presenters::Embedding::Embeds.new
embeds.add_one( &#39;balance&#39;, rendered_balance )
embeds.add_many( &#39;vouchers&#39;, rendered_voucher_array )
</code></pre>

    </div>








    <!-- Method ref -->
    <div class="sectiontitle">Methods</div>
    <dl class="methods">
        <dt>R</dt>
        <dd>
          <ul>
              <li>
                <a href="#method-i-resource_key">resource_key</a>
              </li>
          </ul>
        </dd>
        <dt>V</dt>
        <dd>
          <ul>
              <li>
                <a href="#method-i-validate_many">validate_many</a>,
              </li>
              <li>
                <a href="#method-i-validate_one">validate_one</a>
              </li>
          </ul>
        </dd>
    </dl>










    <!-- Methods -->
      <div class="sectiontitle">Instance Public methods</div>
        <div class="method">
          <div class="title method-title" id="method-i-resource_key">
              <b>resource_key</b>()
            <a href="../../../../classes/Hoodoo/Presenters/Embedding/Embeds.html#method-i-resource_key" name="method-i-resource_key" class="permalink">Link</a>
          </div>

            <div class="description">
              <p>Returns the top-level resource key used for reference data, as per the API
documentation - which is the <a href="../String.html">String</a>
<code>_embed</code>.</p>
            </div>



            <div class="sourcecode">
              <p class="source-link">
                Source:
                <a href="javascript:toggleSource('method-i-resource_key_source')" id="l_method-i-resource_key_source">show</a>
              </p>
              <div id="method-i-resource_key_source" class="dyn-source">
                <pre><span class="ruby-comment"># File lib/hoodoo/presenters/embedding.rb, line 128</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">resource_key</span>
  <span class="ruby-string">&#39;_embed&#39;</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
          </div>
      <div class="sectiontitle">Instance Protected methods</div>
        <div class="method">
          <div class="title method-title" id="method-i-validate_many">
              <b>validate_many</b>( thing )
            <a href="../../../../classes/Hoodoo/Presenters/Embedding/Embeds.html#method-i-validate_many" name="method-i-validate_many" class="permalink">Link</a>
          </div>

            <div class="description">
              <p>Called from <a href="Embeddable.html#method-i-add_many">add_many</a> in the
base class to make sure the right data is being supplied. Raises an
exception if it gets worried.</p>
<dl class="rdoc-list note-list"><dt><code>thing</code>
<dd>
<p>The value that&#39;ll be stored; should be an <a
href="../Array.html">Array</a> of Hashes but only the first array entry is
checked, for speed.</p>
</dd></dl>
            </div>



            <div class="sourcecode">
              <p class="source-link">
                Source:
                <a href="javascript:toggleSource('method-i-validate_many_source')" id="l_method-i-validate_many_source">show</a>
              </p>
              <div id="method-i-validate_many_source" class="dyn-source">
                <pre><span class="ruby-comment"># File lib/hoodoo/presenters/embedding.rb, line 151</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">validate_many</span>( <span class="ruby-identifier">thing</span> )
  <span class="ruby-keyword">unless</span> <span class="ruby-identifier">thing</span>.<span class="ruby-identifier">is_a?</span>( <span class="ruby-operator">::</span><span class="ruby-constant">Array</span> )
    <span class="ruby-identifier">raise</span> <span class="ruby-node">&quot;Hoodoo::Presenters::Embedding::Embeds\#add_many requires an Array, but was given an instance of #{ thing.class }&quot;</span>
  <span class="ruby-keyword">end</span>

  <span class="ruby-keyword">unless</span> <span class="ruby-identifier">thing</span>[ <span class="ruby-number">0</span> ].<span class="ruby-identifier">nil?</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">thing</span>[ <span class="ruby-number">0</span> ].<span class="ruby-identifier">is_a?</span>( <span class="ruby-operator">::</span><span class="ruby-constant">Hash</span> )
    <span class="ruby-identifier">raise</span> <span class="ruby-node">&quot;Hoodoo::Presenters::Embedding::Embeds\#add_many requires an Array of rendered resource Hashes, but the first Array entry is an instance of #{ thing[ 0 ].class }&quot;</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
          </div>
        <div class="method">
          <div class="title method-title" id="method-i-validate_one">
              <b>validate_one</b>( thing )
            <a href="../../../../classes/Hoodoo/Presenters/Embedding/Embeds.html#method-i-validate_one" name="method-i-validate_one" class="permalink">Link</a>
          </div>

            <div class="description">
              <p>Called from <a href="Embeddable.html#method-i-add_one">add_one</a> in the
base class to make sure the right data is being supplied. Raises an
exception if it gets worried.</p>
<dl class="rdoc-list note-list"><dt><code>thing</code>
<dd>
<p>The value that&#39;ll be stored; should be a <a
href="../Hash.html">Hash</a>.</p>
</dd></dl>
            </div>



            <div class="sourcecode">
              <p class="source-link">
                Source:
                <a href="javascript:toggleSource('method-i-validate_one_source')" id="l_method-i-validate_one_source">show</a>
              </p>
              <div id="method-i-validate_one_source" class="dyn-source">
                <pre><span class="ruby-comment"># File lib/hoodoo/presenters/embedding.rb, line 139</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">validate_one</span>( <span class="ruby-identifier">thing</span> )
  <span class="ruby-keyword">unless</span> <span class="ruby-identifier">thing</span>.<span class="ruby-identifier">is_a?</span>( <span class="ruby-operator">::</span><span class="ruby-constant">Hash</span> )
    <span class="ruby-identifier">raise</span> <span class="ruby-node">&quot;Hoodoo::Presenters::Embedding::Embeds\#add_one requires a rendered resource Hash, but was given an instance of #{ thing.class }&quot;</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
          </div>
</div>

    </div>
  </body>
</html>
